<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>汇客CRM管理系统</title>
  <link rel="shortcut icon" href="../../favicon.ico">
  <!-- 引入样式 -->
  <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
  <link rel="stylesheet" href="../../styles/transition.css" />
  <link rel="stylesheet" href="../../styles/element-ui.css" />
  <link rel="stylesheet" href="../../styles/common.css" />
  <link rel="stylesheet" href="../../styles/index.css" />
  <link rel="stylesheet" href="../../styles/modules/login.css" />
  <link rel="stylesheet" href="../../styles/iconfont/iconfont.css" />
  <style>
    .body{
      min-width: 1366px;
    }
  </style>
</head> 

<body>
  <div class="login" id="login-app">
    <div class="login-box">
      <img class="login-l-img" src="../../images/login-l.png" alt="">
      <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
        <div class="login-form-title">
          <img class="logo" src="../../images/login-logo.png" alt="">
          <span class="title-label">汇客CRM系统</span>
        </div>
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号" prefix-icon="iconfont iconcus-user" />
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="loginForm.password"
            type="password"
            auto-complete="off"
            placeholder="密码"
            prefix-icon="iconfont iconcus-pwd"
            @keyup.enter.native="handleLogin"
          />
        </el-form-item>
        <el-form-item prop="code">
          <el-input
            v-model="loginForm.code"
            auto-complete="off"
            placeholder="验证码"
            style="width: 58%"
            @keyup.enter.native="handleLogin"
            prefix-icon="iconfont iconvalidCode"
          >
          </el-input>
          <div class="login-code">
            <img :src="codeUrl" class="login-code-img" @click="getCode">
          </div>
        </el-form-item>
        <!-- <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox> -->
        <el-form-item style="width:100%;">
          <el-button
            :loading="loading"
            class="login-btn"
            size="medium"
            type="primary"
            style="width:100%;"
            @click.native.prevent="handleLogin"
          >
            <span v-if="!loading">登录</span>
            <span v-else>登录中...</span>
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>

  <!-- 开发环境版本，包含了有帮助的命令行警告 -->
  <script src="../../plugins/vue/vue.js"></script>
  <!-- 引入组件库 -->
  <script src="../../plugins/element-ui/index.js"></script>
  <!-- 引入axios -->
  <script src="../../plugins/axios/axios.min.js"></script>
  <script src="../../js/request.js"></script>
  <script src="../../api/login.js"></script>

  <script>
    new Vue({
      el: '#login-app',
      data() {
        return {
          codeUrl: '',
          cookiePassword: '',
          loginForm: {
            username: 'admin',
            password: 'admin123',
            code: '',
            uuid: ''
          },
          loginRules: {
            username: [{ required: true, trigger: 'blur', message: '用户名不能为空' }],
            password: [{ required: true, trigger: 'blur', message: '密码不能为空' }],
            code: [{ required: true, trigger: 'change', message: '验证码不能为空' }]
          },
          loading: false,
          redirect: undefined
        }
      },
      computed: {
      },
      created() {
        this.getCode()
      },
      methods: {
        getCode () {
          getCodeImg().then(res => {
            this.codeUrl = 'data:image/gif;base64,' + res.img
            this.loginForm.uuid = res.uuid
          })
        },
        async handleLogin() {
          this.$refs.loginForm.validate(async (valid) => {
            if (valid) {
              this.loading = true
              let res = await login(this.loginForm)
              if (res.code === 200) {
                localStorage.setItem('Admin-Token',res.token)
                window.location.href= '/index.html'
              } else {
                this.$message.error(res.msg)
                this.loading = false
              }
            }
          })
        }
      }
    })
  </script>
</body>

</html>
